<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Update Conviction History</title>
<script language="javascript" type="text/javascript"
	src="scripts/datetimepicker.js">
</script>
<script language="javascript" type="text/javascript">
var xmlHttp;    

function load()
{
	document.getElementById("user_id").focus();	
}


function showConHistDetails()
{   
		if (typeof XMLHttpRequest != "undefined")
			{      
				xmlHttp= new XMLHttpRequest();      
			}      
		else if (window.ActiveXObject)
			{      
			xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");      
			}      
		if (xmlHttp==null)
			{      
				alert("Browser does not support XMLHTTP Request");      
				return;
			}
		var url="ConvictionController?choice=UpdateConvictionHome&user_id=";
		url +=document.Conviction_update_form.user_id.value;
		xmlHttp.onreadystatechange = userIdEntered;
		xmlHttp.open("POST", url, true);
		xmlHttp.send(null);
}

function userIdValidate()
{
	if((isNaN(document.getElementById("user_id").value)||(document.getElementById("user_id").value==""))==true)
		{	
			document.getElementById("userid_error").innerHTML="<font color=red>Please enter a numeric value</font>";
			document.getElementById("view").disabled=true;
			return false;
		}

	else
		{
			if (typeof XMLHttpRequest != "undefined")
			{      
				xmlHttp= new XMLHttpRequest();      
			}      
				else if (window.ActiveXObject)
			{      
				xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");      
			}      
				if (xmlHttp==null)
			{      
				alert("Browser does not support XMLHTTP Request");      
				return;
			}
			var url="ConvictionController?choice=UpdateUserCheck&user_id=";
			url +=document.Conviction_update_form.user_id.value;
			xmlHttp.onreadystatechange = userIdCheckInDB;
			xmlHttp.open("POST", url, true);
			xmlHttp.send(null);
		}
}

function userIdCheckInDB()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
	{
		var json = eval('(' + xmlHttp.responseText +')');
		var buff="";	  
		document.getElementById("userid_error").innerHTML=json.flag;
		check=json.flag;

		if(check=="false")
			{
				document.getElementById("userid_error").innerHTML=
					"<font color=red>Sorry,userId does not exist.</font>";
				document.getElementById("view").disabled=true;
				return false;
			}
		else if(check=="userHasNoConHist")
		{
			document.getElementById("userid_error").innerHTML=
				"<font color=red>Sorry,there is no conviction history for this userId.</font>";
			document.getElementById("view").disabled=true;
			return false;
		}
		else
		{
			document.getElementById("userid_error").innerHTML="";
			document.getElementById("view").disabled=false;
			return true;
		}
	} 
}
function userIdEntered()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
        	document.getElementById("conviction_history_details").innerHTML=xmlHttp.responseText;
		}         
} 

function showConvictionHistoryDetails(str)
{
	if (typeof XMLHttpRequest != "undefined")
	{      
		xmlHttp= new XMLHttpRequest();      
	}      
else if (window.ActiveXObject)
	{      
	xmlHttp= new ActiveXObject("Microsoft.XMLHTTP");      
	}      
if (xmlHttp==null)
	{      
		alert("Browser does not support XMLHTTP Request");      
		return;
	}
var url="ConvictionController?choice=selected_conHistId&conId=";
url +=str;
xmlHttp.onreadystatechange = allowtoedit;
xmlHttp.open("POST", url, true);
xmlHttp.send(null);
}
 
function allowtoedit()
{
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
		{
        	document.getElementById("update_conviction_history_details").innerHTML=xmlHttp.responseText;
		}         
}

function erase()
{	
	document.getElementById("userid_error").innerHTML="";
	document.getElementById("update_conviction_history_details").innerHTML="";
	document.getElementById("conviction_history_details").innerHTML="";
}

function formReset()
{
	document.getElementById("Conviction_update_form").reset();
	erase();
}
function checkNatureOfConviction()
{
	var x=document.getElementById("natureOfConviction").selectedIndex;
	var y=document.getElementById("natureOfConviction").options;
	{
		if(y[x].text=="Select")
		{
			document.getElementById("select_error").innerHTML="<font color=red>Please select one option</font>";
			return false;
		}
		else
		{	
			document.getElementById("select_error").innerHTML="";
			return true;
		}
	}
}

function checkDateOfConviction()
{
	var flag3=true;
	if(document.getElementById("demo1").value=="")
	{
		document.getElementById("doc_error").innerHTML="<font color=red>Please enter date of conviction</font>";
		flag3=false;
	}
	if(document.getElementById("demo1").value!="")
	{
	
	var x=new Date();
	var today=new Date();
	var n=document.getElementById("demo1").value.split("-");
	var month=new Array();
	month[0]="Jan";
	month[1]="Feb";
	month[2]="Mar";
	month[3]="Apr";
	month[4]="May";
	month[5]="Jun";
	month[6]="Jul";
	month[7]="Aug";
	month[8]="Sep";
	month[9]="Oct";
	month[10]="Nov";
	month[11]="Dec";
	for(i=0;i<12;i++)
	{
	if(n[1]==month[i])
	{
	j=i;

	}
	}
	x.setFullYear(parseInt(n[2]),j,parseInt(n[0]));
	if (x>today)
	  {
		document.getElementById("doc_error").innerHTML="<font size=2px color=red>Please select the Date before today's date</font>";
		flag3=false;
	  }
	else
		document.getElementById("doc_error").innerHTML="";
	return flag3;
	}
}
function checkComments()
{
	if(document.getElementById("comments").value=="")
	{
		document.getElementById("comments_error").innerHTML="<font color=red>Please enter some comments.</font>";
		document.getElementById("submit").disabled=true;
		return false;
	}
	else
	{
		document.getElementById("comments_error").innerHTML="";
		document.getElementById("submit").disabled=false;
		return true;
	}
}
function validation()
{
	var r=confirm("Are you sure you want to submit these details?");
	if (r==true)
	{
		var flag1=checkNatureOfConviction();
		var flag2=checkDateOfConviction();
		var flag3=checkComments();
		if(flag1&&flag2&&flag3)
		{
			return true;
		}
		else
			return false;
	}
	else
		return false;
}

</script>


</head>
<body onload="load()">
<div id="container">

<div id="header">
<div class="clear"></div>
</div>
<div id="nav">
<ul class="sf-menu dropdown">

<li><a href="Home.jsp">Home</a></li>

	<li><a href="#">Proposal</a>
	<ul>
		<li><a href="Quote_viewProposals.jsp">View</a></li>
		<li><a href="Quote_RejectProposal.jsp">Reject</a></li>
	</ul>
	</li>
	<li><a href="#" class="has_submenu">Accident</a>
	<ul>
		<li><a href="AccidentHistory_Register_Accident.jsp">Register</a></li>
		<li><a href="AccidentHistory_ViewAccidentHistory.jsp">Retrieve</a></li>
		<li><a href="AccidentHistory_UpdateAccidentHistory.jsp">Update</a></li>
		<li><a href="AccidentHistory_DeleteAccidentHistory.jsp">Delete</a></li>
	</ul>
	</li>
	<li><a href="#" class="selected">Conviction</a>
	<ul>
		<li><a href="ConvictionHistory_Register.jsp">Register</a></li>
		<li><a href="ConvictionHistory_Retrieve.jsp">Retrieve</a></li>
		<li><a href="ConvictionHistory_Update.jsp" class="selected">Update</a></li>
		<li><a href="ConvictionHistory_DeleteHome.jsp">Delete</a></li>
	</ul>
	</li>
	<li><a href="#" class="has_submenu">Quote</a>
	<ul>
		<li><a href="Quote_generateQuote.jsp">Generate</a></li>
		<li><a href="Quote_viewQuote.jsp">View</a></li>
		<li><a href="Quote_deleteQuote.jsp">Delete</a></li>
	</ul>
	</li>
</ul>
</div>

<div id="body">
<div id="content">

<form name="Conviction_update_form" action="ConvictionController"
	method="post">
<table style="margin-left: 350px">
	<tr>
		<td valign="top">User Id:</td>
		<td><input type="text" name="user_id" id="user_id" 
			onkeypress="return noNumbers(event)" 
			onblur="userIdValidate()"
			onfocus="erase()"></input><br>(e.g. 1234)</td>
		<td valign="top">
		<div id="userid_error" style="width: 200px"></div>
		</td>
	</tr>

	<tr>
		<td colspan="2" align="center"><input type="button" id="view" value="View"
			onclick="showConHistDetails()"  disabled="disabled" class="formbutton">&nbsp;&nbsp;&nbsp;
			<input type="button" id="clear" value="Clear" 
		onclick="formReset()" class="formbutton"></td>	
	</tr>
</table>
<br>
<div id='conviction_history_details' align="center"></div>
</form>
<br>
<div id='update_conviction_history_details'></div>
<br/><br/><br/><br/>
</div>
</div>
</div>

</body>
</html>